package d_direct;

import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import org.junit.Test;
import utils.RabbitMQUtils;

public class Producer {
    @Test
    public void sendMessage() throws Exception {
        Connection connection = RabbitMQUtils.getConnection();
        Channel channel = connection.createChannel();
        String exchangeName = "logs_direct";
        channel.exchangeDeclare(exchangeName, BuiltinExchangeType.DIRECT);
        //第二个参数：路由 key
        channel.basicPublish(exchangeName, "info", null, ("我是一个直连类型的交换机消息-routingKey:" + "info").getBytes());
        channel.basicPublish(exchangeName, "warm", null, ("我是一个直连类型的交换机消息-routingKey:" + "warm").getBytes());
        channel.basicPublish(exchangeName, "debug", null, ("我是一个直连类型的交换机消息-routingKey:" + "debug").getBytes());
        channel.basicPublish(exchangeName, "error", null, ("我是一个直连类型的交换机消息-routingKey:" + "error").getBytes());

        System.out.println("消息发送成功");
        RabbitMQUtils.closeChannelAndConnection(channel, connection);
    }
}